﻿using System.Collections.Generic;
using System.Linq;
using DailyPoetryX.Services;

namespace DailyPoetryX.Models {
    /// <summary>
    /// 菜单项。
    /// </summary>
    public class MenuItem {
        /// <summary>
        /// 菜单项。
        /// </summary>
        private MenuItem() {
        }

        /// <summary>
        /// 标题。
        /// </summary>
        public string Title { get; private set; }

        /// <summary>
        /// 页面键。
        /// </summary>
        public string PageKey { get; private set; }

        /// <summary>
        /// 菜单项List。
        /// </summary>
        public static IList<MenuItem> ItemList { get; } = new List<MenuItem> {
            new MenuItem {
                Title = "今日推荐",
                PageKey = RootNavigationServiceConstants.TodayPage
            },
            new MenuItem {
                Title = "诗词搜索",
                PageKey = RootNavigationServiceConstants.QueryPage
            },
            new MenuItem {
                Title = "我的收藏",
                PageKey = RootNavigationServiceConstants.FavoritePage
            },
            new MenuItem {
                Title = "数据同步",
                PageKey = RootNavigationServiceConstants.SyncPage
            },
            new MenuItem {
                Title = "关于", PageKey = RootNavigationServiceConstants.AboutPage
            }
        };

        /// <summary>
        /// 标题-菜单项字典。
        /// </summary>
        private static Dictionary<string, MenuItem> TitleMenuItemDictionary =
            ItemList.ToDictionary(p => p.PageKey, p => p);

        /// <summary>
        /// 根据页面键获得菜单项。
        /// </summary>
        /// <param name="pageKey">页面键。</param>
        /// <returns>菜单项。</returns>
        public static MenuItem GetMenuItem(string pageKey) =>
            TitleMenuItemDictionary.ContainsKey(pageKey)
                ? TitleMenuItemDictionary[pageKey]
                : null;
    }
}